package main

import "net"

type User struct {
	Name string
	Addr string
	C chan string
	conn net.Conn
}

//创建一个用户的api
func NewUser(con net.Conn) *User {

	userAddr := con.RemoteAddr().String()
	user := &User{
		Name: userAddr,
		Addr: userAddr,
		C	: make(chan string),
		conn: con,
	}

	go user.ListenMessage()
	return user
}

//监听当前user channel 一旦有消息发送给客户端
func (u *User) ListenMessage() {

	for  {
		msg := <-u.C
		u.conn.Write([]byte(msg + "\n"))
	}
}

